package spec.computer_statistics;
import static org.junit.Assert.*;

import java.util.Map;

import org.junit.After;
import org.junit.Before;
import org.junit.Test;

import br.ufpe.cin.dsoa.qos.service.registry.QosServiceRegistry;
import br.ufpe.cin.dsoa.qos.service.registry.impl.QoSAttribute;
import br.ufpe.cin.dsoa.qos.service.registry.impl.QosServiceRegistryImpl;
import br.ufpe.cin.dsoa.qos.service.registry.impl.Statistics;


public class ComputerStatistics {

	QosServiceRegistry serviceRegistry;
	@Before
	public void setUp() throws Exception {
		this.serviceRegistry = new QosServiceRegistryImpl();

		for(int i = 0; i < 2; i++) { //service
			for(int j = 0; j < 4; j++) { //response time
				serviceRegistry.addQosData(new QoSAttribute("serviceId:" + i, "operation:A", "consumerId:1", 1 + j, "ResponseTime"));
			}
			serviceRegistry.addQosData(new QoSAttribute("serviceId:" + i, "consumerId:1", 87, "Availability"));
			serviceRegistry.addQosData(new QoSAttribute("serviceId:" + i, "consumerId:1", 3 + i, "Throughput"));
		}
	}

	@After
	public void tearDown() throws Exception {
		this.serviceRegistry = null;
	}

	@Test
	public void testGetMean() {
		Map<String, Statistics> historical = this.serviceRegistry.getHistoricalData("serviceId:0");
		Statistics stat = historical.get("operation:A.ResponseTime");
		double mean = stat.getMean();
		assertEquals(2.5, mean, 0);
	}
	
	@Test
	public void testGetMax() {
		Map<String, Statistics> historical = this.serviceRegistry.getHistoricalData("serviceId:0");
		Statistics stat = historical.get("operation:A.ResponseTime");
		double max = stat.getMax();
		assertEquals(4, max, 0);
	}
	
	@Test
	public void testGetMin() {
		Map<String, Statistics> historical = this.serviceRegistry.getHistoricalData("serviceId:0");
		Statistics stat = historical.get("operation:A.ResponseTime");
		double min = stat.getMin();
		assertEquals(1, min, 0);
	}
}
